<?php
/*
	$Id: admincp_contribute.php 12844 2012-08-21 gy $
*/

if(!defined('IN_UCHOME') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}

//权限
if(!$allowmanage = checkperm('managecontribute')) {
	cpmessage('no_authority_management_operation');
}


if(!empty($_POST['cid'])){
	$cid = intval($_POST['cid']);
	$checks = intval($_POST['checks']);
	updatetable('contribute', array('checks'=>$checks), array('cid'=>$cid));
	cpmessage('do_success', 'admincp.php?ac=contribute');
}

if($_GET['op'] == 'checks') {	
	if(!$allowmanage){cpmessage('no_authority_management_operation');}
	if(!empty($_GET['cid'])){$actives = array('checks' => 'class="active"');}
	$cid = intval($_GET['cid']);
	$query = $_SGLOBAL['db']->query("SELECT c.*,t.type,f.picid,f.filename,f.fileext FROM ".tname('contribute')." AS c LEFT JOIN ".tname('contribute_type')." AS t ON c.typeid = t.tid LEFT JOIN ".tname('files')." AS f ON c.file = f.filepath WHERE c.cid =".$cid);
	$cont_look = $_SGLOBAL['db']->fetch_array($query);
}else {
		
	$mpurl = 'admincp.php?ac=contribute';
	
	//处理搜索
	$intkeys = array('uid', 'uid');
	$strkeys = array();
	$randkeys = array(array('sstrtotime','ontime'));
	$likekeys = array();
	$results = getwheres($intkeys, $strkeys, $randkeys, $likekeys);
	$wherearr = $results['wherearr'];
	$wheresql = empty($wherearr)?'1':implode(' AND ', $wherearr);
	$mpurl .= '&'.implode('&', $results['urls']);
	
	//排序
	$orders = getorders(array('ontime'), 'cid');
	$ordersql = $orders['sql'];
	if($orders['urls']) $mpurl .= '&'.implode('&', $orders['urls']);
	$orderby = array($_GET['orderby']=>' selected');
	$ordersc = array($_GET['ordersc']=>' selected');
	
	//激活
	if(empty($_GET['cid'])) {
		$actives = array('all' => 'class="active"');
	}
	
	$perpage = empty($_GET['perpage'])?0:intval($_GET['perpage']);
	if(!in_array($perpage, array(20,50,100))) $perpage = 20;
	
	$page = empty($_GET['page'])?1:intval($_GET['page']);
	if($page<1) $page = 1;
	$start = ($page-1)*$perpage;
	//检查开始数
	ckstart($start, $perpage);

	$count = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM ".tname('contribute')." WHERE $wheresql"), 0);
	$selectsql = 'c.*,t.*';

	$mpurl .= '&perpage='.$perpage;
	$perpages = array($perpage => ' selected');
	
	$list = array();
	$multi = '';
	$managebatch = checkperm('admin');
	$allowbatch = true;
	if($count) {
		
		$query = $_SGLOBAL['db']->query("SELECT $selectsql FROM ".tname('contribute')." AS c LEFT JOIN ".tname('contribute_type')." AS t ON c.typeid = t.tid WHERE $wheresql $ordersql LIMIT $start,$perpage");
		while ($value = $_SGLOBAL['db']->fetch_array($query)) {
			realname_set($value['uid'], $value['username'], $value['username'], 1);
			if(!$managebatch && $value['uid'] != $_SGLOBAL['supe_uid']) {
				$allowbatch = false;
			}
			$list[] = $value;
		}
		$multi = multi($count, $perpage, $page, $mpurl);
	}
	
	if($perpage > 100) {
		$count = count($list);
	}
	
	realname_get();
}

?>